package sort_finished;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class T169 {

    public int majorityElement(int[] nums) {
        int majority = nums.length/2; //4
        int whatever = 0;
        if (nums.length % 2 == 0) {
            whatever = nums.length - 1;
        } else {
            whatever = majority;
        }
        Arrays.sort(nums);
        for (int i = 0; i <= whatever; i++) {  //i max = 4  4+4=8
            if (nums[i] == nums[i+majority]) {
                return nums[i];
            }
        }
        return 0;
    }

}
